<!--&#45;&#45;chongzhi-->
<!-- 首页 -->
<template>
	<view class="home-wrap u-m-b-20">
		<wanl-navbar :isBack="true"
		              :showGongNeng="true"
		>
			<text
				slot="content"
				style="width: 100%; text-align: center;padding-left: 20rpx;font-size:30rpx"
			>
				{{'金元宝抵扣'}}
			</text>
		</wanl-navbar>
		<view class="content-box u-p-10 u-m-l-20 u-m-r-20">
			<view class="chongzhi_top">
				<view class="yuanbao"></view>
<!--				<view class="shengyu" style="color: #FC6A24">剩余金元宝: {{ removeTrailingZeros(yuanbao) }} 个 </view>-->
			</view>
			<view class="chongzhi_content">
				<view class="chongzhi_title">
					<text style="font-size: 30rpx;font-weight: bold;margin-right: 6rpx;height: 100%;display: flex;align-items: flex-end;line-height: 30px;">¥</text>
					<text style="font-size: 54rpx;font-weight: bold;height: 100%;display: flex;align-items: flex-end">{{money}}</text>
				</view>
				<view class="chongzhi_title" style="color: #666666;font-size: 28rpx">该商品需要花费 <text style="color: #FC6A24">{{removeTrailingZeros(huafei)}}</text>  个金元宝</view>
			</view>
		
			<button class="u-reset-button login-btn-start" @tap="gochongzhi">
				确认抵扣
			</button>
		</view>
	</view>
</template>

<script>

import {mapMutations, mapActions, mapState, mapGetters} from 'vuex';

let chart = null
export default {
	data() {
		return {
			chongzhiList:[
			],
			currentIndex:'',
			money:'',
			huafei:'',
			yuanbao:'',
			type:'',
			order_id:'',
			payData:''
		};
	},
	computed: {
	},
	onPullDownRefresh() {
	
	},
	
	onShow() {
		this.init();
	},
	onHide() {
	
	},
	onLoad(options){
		this.money = options.money;
		this.huafei = options.huafei;
		this.order_id = options.order_id;
		if(options.payData){
			this.payData = options.payData
		}
		this.type = 'combination';
	},
	methods: {
		removeTrailingZeros(num) {
			return Number(num.replace(/\.?0+$/, ''));
		},
		// 初始化
		init() {
			this.initdata()
		},
		initdata(){
			let that = this;
			uni.request({
				url:'/wanlshop/user/profile',
				method: 'POST',
				data:{
				},
				success:(res)=>{
					console.log("===信息。",res);
					this.yuanbao = res.data.yuanbao;
					uni.setStorageSync("yuanbao",res.data.yuanbao)
				}
			});
		},
		chooseOne(item,index){
			this.currentIndex = index;
			this.money = this.removeTrailingZeros(item.money);
			this.money_id = item.id;
			this.yuanbao_num = this.removeTrailingZeros(item.name);
		},
		gochongzhi(){
			let that = this;
			if(that.money){
				uni.request({
					url:'/Wanlshop/Pay/payment',
					method: 'POST',
					data:{
						type:this.type,
						order_id:this.order_id,
						token:uni.getStorageSync("wanlshop:user").token,
						gold:this.huafei,
					},
					success:(res)=>{
						if(this.payData){
							that.$wanlshop.to(`/pages/apps/jinyuanbao/generateTwoDimensionalCode?money=${that.removeTrailingZeros(that.money)}&order_id=${res.data.order_no}&user_id=${uni.getStorageSync("wanlshop:user").id}&path=${res.data.gold_qrcode}&yuanbao_num=${that.removeTrailingZeros(that.huafei)}&payData=${this.payData}`)
						}else{
							that.$wanlshop.to(`/pages/apps/jinyuanbao/generateTwoDimensionalCode?money=${that.removeTrailingZeros(that.money)}&order_id=${res.data.order_no}&user_id=${uni.getStorageSync("wanlshop:user").id}&path=${res.data.gold_qrcode}&yuanbao_num=${that.removeTrailingZeros(that.huafei)}`)
							
						}
					}
				});
			}else{
				uni.showToast({
					title:'请选择充值金额',
					icon:'none'
				})
			}
			
		},
	}
};
</script>

<style lang="scss" scoped>
.home-wrap{
	//background:rgba(250, 250, 251, 1);
}
.uni-ec-canvas {
	width: 100%;
	height: 400rpx;
	display: block;
}
.uni-ec-canvas-bing {
	width: 100%;
	height: 200rpx;
	display: block;
}
page {
	background: #fff;
}
.login-btn-start {
	width: 90%;
	margin: 30rpx auto 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 86rpx;
	background: linear-gradient(90deg, #FC6A24, #FC6A24);
	border-radius: 38rpx;
	font-size: 26rpx;
	font-weight: 500;
	color: #ffffff;
	position: fixed;
	bottom: 60rpx;
	left: 4.5%;
}
.chongzhi_top{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	background: url("https://d-shenhuashop.bigchun.com/h5test/yuanbao/shangpin/yuanbaoPay.png") no-repeat center;
	background-size: 100%;
	height: 460rpx;
	.yuanbao{
		width: 180rpx;
		height: 240rpx;
		margin-bottom: 40rpx;
	
	}
	.shengyu{
		color:#fff;
		font-size: 30rpx;
	}
}
.chongzhi_content{
	width: 95%;
	height: 440rpx;
	background: #fff;
	background-size: 100%;
	border-radius: 30rpx;
	background-position-y: 0;
	overflow: hidden;
	padding: 20rpx;
	.chongzhi_group{
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
		.chongzhi_item{
			width: 30%;
			background: #F6F6F6;
			border-radius: 20rpx;
			color: #666666;
			padding: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			margin-top: 20rpx;
			font-size: 34rpx;
			border: 1rpx solid transparent;
		}
		.active{
			background: #F9E8E0;
			color: #FF6121;
			border: 1rpx solid #FD6B25;
		}
	}
	.chongzhi_title{
		margin-top: 20rpx;
		padding-left: 20rpx;
		font-size: 34rpx;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}
}
.chongzhi_tishi{
	width: 95%;
	background: #F9E8E0;
	border-radius: 18rpx;
	padding: 30rpx 30rpx;
	color: #FF6121;
	margin: 0 auto;
	display: flex;
	justify-content: flex-start;
	align-items: center;
}
.waring{
	background: url("https://d-shenhuashop.bigchun.com/h5test/yuanbao/chongzhi/jinggao.png") no-repeat center;
	background-size: 100%;
}
</style>
